package com.scorpio.web.controller.complain;

import java.util.List;

import com.scorpio.common.core.page.TableDataInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.scorpio.common.annotation.Log;
import com.scorpio.common.enums.BusinessType;
import com.scorpio.common.annotation.RepeatSubmit;
import com.scorpio.complain.domain.BizComplainEntity;
import com.scorpio.complain.service.IBizComplainService;
import com.scorpio.common.core.controller.BaseController;
import com.scorpio.common.core.domain.AjaxResult;
import com.scorpio.common.utils.poi.ExcelUtil;
import com.scorpio.common.utils.verification.AddGroup;
import com.scorpio.common.utils.verification.DefaultGroup;
import com.scorpio.common.utils.verification.UpdateGroup;

/**
 * 投诉客服Controller
 *
 * @author scorpio
 * @date 2020-10-16
 */
@RestController
@RequestMapping("/complain/complain")
public class BizComplainController extends BaseController {

    @Autowired
    private IBizComplainService service;

    /**
     * 查询投诉客服列表
     */
    @PreAuthorize("@ss.hasPermi('complain:complain:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizComplainEntity entity) {
        startPage();
        List<BizComplainEntity> list = service.selectList(entity);
        return getDataTable(list);
    }

    /**
     * 导出投诉客服列表
     */
    @PreAuthorize("@ss.hasPermi('complain:complain:export')")
    @Log(title = "投诉客服", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizComplainEntity entity) {
        List<BizComplainEntity> list = service.selectList(entity);
        ExcelUtil<BizComplainEntity> util = new ExcelUtil<>(BizComplainEntity.class);
        return util.exportExcel(list, "complain");
    }

    /**
     * 获取投诉客服详细信息
     */
    @PreAuthorize("@ss.hasPermi('complain:complain:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(service.selectById(id));
    }

    /**
     * 新增投诉客服
     */
    @PreAuthorize("@ss.hasPermi('complain:complain:add')")
    @Log(title = "投诉客服", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated(value = {DefaultGroup.class, AddGroup.class}) @RequestBody BizComplainEntity entity) {
        return toAjax(service.save(entity));
    }

    /**
     * 修改投诉客服
     */
    @PreAuthorize("@ss.hasPermi('complain:complain:edit')")
    @Log(title = "投诉客服", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated(value = {DefaultGroup.class, UpdateGroup.class}) @RequestBody BizComplainEntity entity) {
        return toAjax(service.update(entity));
    }

    /**
     * 删除投诉客服
     */
    @PreAuthorize("@ss.hasPermi('complain:complain:remove')")
    @Log(title = "投诉客服", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(service.deleteByIds(ids));
    }
}
